package com.fr.base.core.util;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;

public class SerializationUtils
{
  public static Object clone(Serializable paramSerializable)
  {
    return deserialize(serialize(paramSerializable));
  }

  public static void serialize(Serializable paramSerializable, OutputStream paramOutputStream)
  {
    if (paramOutputStream == null)
      throw new IllegalArgumentException("The OutputStream must not be null");
    ObjectOutputStream localObjectOutputStream = null;
    try
    {
      localObjectOutputStream = new ObjectOutputStream(paramOutputStream);
      localObjectOutputStream.writeObject(paramSerializable);
    }
    catch (IOException localIOException1)
    {
    }
    finally
    {
      try
      {
        if (localObjectOutputStream != null)
          localObjectOutputStream.close();
      }
      catch (IOException localIOException2)
      {
      }
    }
  }

  public static byte[] serialize(Serializable paramSerializable)
  {
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream(512);
    serialize(paramSerializable, localByteArrayOutputStream);
    return localByteArrayOutputStream.toByteArray();
  }

  public static Object deserialize(InputStream paramInputStream)
  {
    if (paramInputStream == null)
      throw new IllegalArgumentException("The InputStream must not be null");
    ObjectInputStream localObjectInputStream = null;
    try
    {
      localObjectInputStream = new ObjectInputStream(paramInputStream);
      Object localObject1 = localObjectInputStream.readObject();
      return localObject1;
    }
    catch (ClassNotFoundException localClassNotFoundException)
    {
    }
    catch (IOException localIOException1)
    {
    }
    finally
    {
      try
      {
        if (localObjectInputStream != null)
          localObjectInputStream.close();
      }
      catch (IOException localIOException2)
      {
      }
    }
  }

  public static Object deserialize(byte[] paramArrayOfByte)
  {
    if (paramArrayOfByte == null)
      throw new IllegalArgumentException("The byte[] must not be null");
    ByteArrayInputStream localByteArrayInputStream = new ByteArrayInputStream(paramArrayOfByte);
    return deserialize(localByteArrayInputStream);
  }

  public static Object deserializable(File paramFile)
    throws IOException, ClassNotFoundException
  {
    return deserialize(new FileInputStream(paramFile));
  }

  public static void serializable(Serializable paramSerializable, File paramFile)
    throws IOException
  {
    serialize(paramSerializable, new FileOutputStream(paramFile));
  }
}